<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <script type="text/javascript" src="toolkit.js"></script>
    <script type="text/javascript" src="scanner.js"></script>
    <script type="text/javascript" src="parser.js"></script>
    <script type="text/javascript" src="syntax.js"></script>
    <script type="text/javascript" src="translator.js"></script>
    <script type="text/javascript" src="runtime-detail.js"></script>
    <script type="text/javascript" src="runtime-core.js"></script>
    <script type="text/javascript" src="runtime-prelude.js"></script>
    <script type="text/javascript" src="runtime-tools.js"></script>
    <script type="text/kumachan" src="modules/calc.k"></script>
    <script type="text/javascript">
      function init () {
          function load (file) {
              let xhr = new XMLHttpRequest()
              console.log(`loading ${file}`)
              xhr.open('GET', file)
              xhr.send()
              xhr.addEventListener('readystatechange', function (ev) {
                  if (this.readyState == 4 && this.status == 200) {
                      let k_code = this.responseText
                      console.log(`parsing ${file}`)
                      let t0 = performance.now()
                      let tree = parse(k_code)
                      let t1 = performance.now()
                      console.log("time", t1-t0)
                      console.log(tree)
                      /*
                      console.log(print_tree(tree))
                      let code = translate(tree)
                      let script = document.createElement('script')
                      script.type = 'text/javascript'
                      script.innerText = code
                      document.head.appendChild(script)
                      */
                  }
              })
          }
          let tags = document.querySelectorAll('script[type="text/kumachan"]')
          map(tags, tag => load(tag.src))
      }
      window.addEventListener('DOMContentLoaded', init)
    </script>
  </head>
  <body>
    <h1>Test Page</h1>
    <p>The quick brown fox jumps over lazy dog.</p>
  </body>
</html>
